package sdk.webview.fmc.com.fmcsdk.check.persenter;


import sdk.webview.fmc.com.fmcsdk.base.BaseData;
import sdk.webview.fmc.com.fmcsdk.base.BasePresenter;
import sdk.webview.fmc.com.fmcsdk.base.UserApi;
import sdk.webview.fmc.com.fmcsdk.bean.DDTypeBean;
import sdk.webview.fmc.com.fmcsdk.bean.StaffBean;
import sdk.webview.fmc.com.fmcsdk.check.bean.StaffteamBean;
import sdk.webview.fmc.com.fmcsdk.check.bean.WorkStatusBean;
import sdk.webview.fmc.com.fmcsdk.check.interfaces.PeopleSelectView;
import sdk.webview.fmc.com.fmcsdk.util.Url;
import sdk.webview.fmc.com.fmcsdk.util.UserHelper;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.observer.ResponseTransformer;
import sdk.webview.fmc.com.fmcsdk.util.retrofit2.subscriber.ResponseSubscriber;

/**
 * Created by ydm on 2017/9/14.
 */

public class PeopleSelectPersenter extends BasePresenter<PeopleSelectView> {

    public void getStaffTeamList(String projid, String baseBizTypeId) {
        view.showLoading();
        getApi(UserApi.class).apiStaffTeamList(getDefaultAddress() + Url.GET_STAFFTEAM_LIST,UserHelper.getToken(),projid,baseBizTypeId)
                .compose(new ResponseTransformer<>(this.<StaffteamBean>bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<StaffteamBean>(view) {
                    @Override
                    public void success(StaffteamBean baseData) {
                        view.getStaffTeamList(baseData);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);

                    }

                    @Override
                    public void onRequestAgain() {

                    }
                });
    }


    public void getWorkStatus(String staffStructureId,String orgType, String userName) {
        view.showLoading();
        getApi(UserApi.class).apiWorkStatus(getDefaultAddress() + Url.GET_WORK_STATUS,UserHelper.getToken(),staffStructureId, orgType,userName)
                .compose(new ResponseTransformer<>(this.bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<WorkStatusBean>(view) {
                    @Override
                    public void success(WorkStatusBean baseData) {
                        view.getWoStatusContactPersonList(baseData.getRecords());
                        view.hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.hideLoading();
                    }

                    @Override
                    public void onRequestAgain() {

                    }
                });
    }

    public void getStaff(String projid,String id) {
        getApi(UserApi.class).apiStaff(getDefaultAddress() + Url.GET_WORK_STAFF,UserHelper.getToken(),projid, id)
                .compose(new ResponseTransformer<>(this.bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<StaffBean>(view) {
                    @Override
                    public void success(StaffBean baseData) {
                        if ( null != baseData.getRecord()){
                            view.getWorkStaff(baseData.getRecord());
                        }
                        view.hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.hideLoading();
                    }

                    @Override
                    public void onRequestAgain() {

                    }
                });
    }


    public void getRedeployReason() {
        getApi(UserApi.class).apiRedeployReason(getDefaultAddress() + Url.GET_REDEPLOY_REASON,UserHelper.getToken(),"REFUSE_REMARK")
                .compose(new ResponseTransformer<>(this.bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<DDTypeBean>(view) {
                    @Override
                    public void success(DDTypeBean baseData) {
                        if ( null != baseData.getRecords()){
                            view.getRedeployReason(baseData.getRecords());
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);

                    }

                    @Override
                    public void onRequestAgain() {

                    }
                });
    }


    public void getQuestRedeploy(String projid, String id, String taskId, String staffId, String principalId, String remark, String sendStaffId, String newStaffTeamId, String code) {
        view.showLoading();
        getApi(UserApi.class).apiQuestRedeploy(getDefaultAddress() + Url.GET_QUEST_REDEPLOY,UserHelper.getToken(),projid,id,taskId,staffId,principalId,remark,sendStaffId,newStaffTeamId,code,"REASSIGH_REMARK")
                .compose(new ResponseTransformer<>(this.bindToLifeCycle()))
                .subscribe(new ResponseSubscriber<BaseData>(view) {
                    @Override
                    public void success(BaseData baseData) {
                        view.getQuestRedeploy();
                        view.hideLoading();
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                        view.hideLoading();
                    }

                    @Override
                    public void onRequestAgain() {

                    }
                });
    }

}
